package com.ccys.cms.service.productAndService.impl;

import com.ccys.cms.service.productAndService.ProductGroupService;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.web.productAndService.ProductGroupDto;
import com.ccys.db.entity.TblProductGroup;
import com.ccys.db.mapper.TblProductGroupMapper;
import com.ccys.db.page.PageDto;
import com.ccys.db.rely.service.impl.BaseServiceImpl;
import com.ccys.db.vo.web.productAndService.ProductGroupVo;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ProductGroupServiceImpl extends BaseServiceImpl<TblProductGroup> implements ProductGroupService {

    @Resource
    private TblProductGroupMapper mapper;

    @Override
    public ResponseResult getPage(ProductGroupDto dto) {
        PageDto.startPage();
        //根据当前用户groupid
        //超级管理员的区分 (超级管理员没有groupId 不会进查询条件)
        if (StringUtils.isEmpty(dto.getGroupId())) {
            String groupId = dto.getGroupId();
            dto.setGroupId(groupId);
        }
        List<ProductGroupVo> list = mapper.getList(dto);
        PageInfo<ProductGroupVo> info = new PageInfo<>(list);
        return ResponseResult.success(info);
    }
}
